﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[CreateUser]
	-- Add the parameters for the stored procedure here
	@Email nvarchar(100),
	@Handphone nvarchar(15) ,
	@Name nvarchar(100) ,
	@Password nvarchar(300),
	@ResultType nvarchar(30) OUTPUT,
	@ResultMessage nvarchar(50) OUTPUT
AS
BEGIN TRANSACTION
    IF  NOT EXISTS(SELECT * FROM Mobile_User WHERE Email = @Email)
    BEGIN
        --This environmentName does not exists, so insert...
        INSERT INTO Mobile_User (Email,Handphone,Name,Password)
        values (@Email,@Handphone,@Name,@Password)
        --SELECT  @Email, @Handphone

            -- I get an error if I decomment the 2 lines underneath :-(
        SET @ResultType = 'Success'
        SET @ResultMessage = 'User Created'
    END
    ELSE
    BEGIN
        --This environmentName does not exists so throw error

        SET @ResultType = 'Error'
        SET @ResultMessage = 'Email already exists'
    END
    SELECT	@ResultType as N'@ResultType',
		@ResultMessage as N'@ResultMessage'
COMMIT    
